{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9ce5d9ac",
   "metadata": {},
   "source": [
    "### for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "12ed7869",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "16b31460",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d7c5ef2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 9]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "77c8fd73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-20, -50, -80]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(-20,-100,-30))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "322fd22f",
   "metadata": {},
   "source": [
    "### for循环配合内置函数range(）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "67420085",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = ['xiaoming','xiaohong','lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "78d8d644",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xiaoming---20210001\n",
      "xiaohong---20210002\n",
      "lihua---20210003\n"
     ]
    }
   ],
   "source": [
    "# for 遍历数据的重要操作\n",
    "for k,i in enumerate(names):\n",
    "    print(i+\"---\"+str(20210000+k+1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4dc1c96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd second. ---当前时间节点的秒钟: 0\n",
      "等待的随机时间 13\n",
      "This second seems a little odd. ---当前时间节点的秒钟: 13\n",
      "等待的随机时间 46\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds= [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\",\"---当前时间节点的秒钟:\",right_this_second)\n",
    "    else:\n",
    "        print(\"Not an odd second.\",\"---当前时间节点的秒钟:\",right_this_second)\n",
    "        # 增加等待时间\n",
    "    wait_time = random.randint(1,60)\n",
    "    print(\"等待的随机时间\",wait_time)\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18b33fa5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
